<?php

	/* SVN FILE: $Id: company_suggestions.php 36 2011-01-14 17:02:10Z andreoletti $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: andreoletti $
	 * @version $Revision: 36 $
	 * @lastrevision $Date: 2011-01-14 18:02:10 +0100 (ven, 14 gen 2011) $
	 * @filesource $URL: http://svn.fletchlynd.com/arcadia/trunk/addressbook/company_suggestions.php $
	 */
	 
	require_once 'include/functions.php';
	require_once 'include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';
	
	$aItems = array();

	fnGetValueFromGET(array('term'));
	
	if (!isset($sViewItemLink) || empty ($sViewItemLink)) {
		$sViewItemLink = $aTABLE[$sTABLE_DEFAULT]['sViewItemLink'];
	}
	
	fnViewConst($sViewItemLink);
	
	if (isset($term) && !empty($term))
		$sQuery = "SELECT `sCompany` FROM `$sViewSelectFrom` WHERE `sCompany` LIKE '%$term%' AND `sCompany` != '' GROUP BY `sCompany` ORDER BY `sCompany`";
	else
		$sQuery = "SELECT `sCompany` FROM `$sViewSelectFrom` WHERE `sCompany` != '' GROUP BY `sCompany` ORDER BY `sCompany`";
	
	if (isset($sQuery) && !empty($sQuery)){
		$aResult = custom_mysql_query ($sQuery);
		while ($aRow = mysql_fetch_array ($aResult)) {
			$aItems[] = array("value" => strip_tags($aRow['sCompany']));
		}
	}

	echo array_to_json($aItems);
	die();
?>


